package com.qingcloud.adminbackend.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import com.qingcloud.adminbackend.base.AjaxResult;
import com.qingcloud.adminbackend.entity.config.SysDictionaryConfig;
import com.qingcloud.adminbackend.entity.equipment.*;
import com.qingcloud.adminbackend.entity.stationequipment.OptStationEquipment;
import com.qingcloud.adminbackend.entity.sysstation.EquipmentSyncDTO;
import com.qingcloud.adminbackend.entity.sysstation.StationMiniInfo;
import com.qingcloud.adminbackend.pojo.equipment.EquipmentDecodeMessage;
import com.qingcloud.adminbackend.pojo.equipment.EquipmentDecoder;
import com.qingcloud.adminbackend.pojo.equipment.GatewayInfo;
import com.qingcloud.adminbackend.entity.equipment.*;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.Set;

/**
 * <p>
 * 设备表基本信息表 服务类
 * </p>
 *
 * @author luozehua
 * @since 2018-11-19
 */
public interface ISysEquipmentService extends IService<SysEquipment> {
    /**
     * 设备池内的设备
     *
     * @param equipmentListBO
     * @return
     */
    List<EquipmentListDTO> equipmentPool(EquipmentListBO equipmentListBO);

    /**
     * 删除订单关联的设备
     *
     * @param equipmentDTO
     * @return
     */
    AjaxResult deleteEquipmentsByIds(EquipmentDTO equipmentDTO);

    /**
     * 订单关联设备Api(从设备池移入)
     *
     * @param equipmentDTO
     * @return
     */
    AjaxResult orderToEquipment(EquipmentDTO equipmentDTO, String userId);

    /**
     * 网格化设备、监测点批量导入
     *
     * @param file
     * @return
     */
//    AjaxResult equipmentStationExcelWGH(MultipartFile file, String orderId, String userId) throws IOException, InvalidFormatException;

    /**
     * 从设备池批量导入
     *
     * @param file
     * @param orderId
     * @return
     */
    AjaxResult equipmentPoolExcel(MultipartFile file, String orderId, String userId) throws IOException, InvalidFormatException;

    /**
     * 批量导入设备
     *
     * @param file
     * @param orderId
     * @param userId
     * @return
     * @throws IOException
     * @throws InvalidFormatException
     */
    AjaxResult equipmentExcel(MultipartFile file, String orderId, String userId) throws IOException, InvalidFormatException;

    /**
     * 批量导入监测点
     *
     * @param file
     * @param orderId
     * @param userId
     * @return
     * @throws IOException
     * @throws InvalidFormatException
     */
//    AjaxResult stationExcel(MultipartFile file, String orderId, String userId) throws IOException, InvalidFormatException;

    /**
     * 健康空气设备、监测点批量导入
     *
     * @param file
     * @return
     */
    AjaxResult equipmentStationExcelJKKQ(MultipartFile file, String orderId, String userId) throws IOException, InvalidFormatException;

    /**
     * 健康空气监测点批量导入
     *
     * @param file
     * @return
     */
    AjaxResult stationExcelJKKQ(MultipartFile file, String orderId, String userId) throws IOException, InvalidFormatException;

    /**
     * 查询没有绑定的设备列表
     *
     * @param currentPage
     * @param perPage
     * @param userId
     * @return
     */
    IPage<UnbindEquipmentDTO> findUnbindEquipment(Integer currentPage, Integer perPage, String userId);

    /**
     * 订单内设备
     *
     * @param equipmentListBO
     * @return
     * @author liyuhong
     */
    List<EquipmentListDTO> orderEquipment(EquipmentListBO equipmentListBO);

    /**
     * 订单内设备移入移出
     *
     * @param equipmentDTO
     * @param userId
     * @return
     * @author liyuhong
     */
    AjaxResult orderEquipmentMoveToYichu(EquipmentDTO equipmentDTO, String userId);

    /**
     * 设备池的设备列表Api
     *
     * @param equipmentPoolListBO
     * @return
     * @author liyuhong
     */
    IPage<EquipmentPoolListDTO> equipmentPoolList(EquipmentPoolListBO equipmentPoolListBO);

    /**
     * 设备解除绑定
     */
    int unbind(OptStationEquipment sysStationEquipment, String userId);

    /**
     * 设备绑定
     */
    Integer bind(OptStationEquipment sysStationEquipment, String userId);

    /**
     * 更换绑定
     *
     * @param sysStationEquipment
     * @param userId
     */
    Integer changeBind(OptStationEquipment sysStationEquipment, String userId);

    /**
     * 更换站点主设备绑定
     *
     * @param sysStationEquipment
     * @param userId
     */
    Integer replaceBind(OptStationEquipment sysStationEquipment, String userId);

    /**
     * 获取可用工作模式
     */
    List<SysDictionaryConfig> findEnableWorkMode(String equipmentId);


    /**
     * 查询设备列表
     *
     * @param equipmentListPara
     * @param userId
     */
    IPage<EquipmentListDTO> listEquipment(EquipmentListPara equipmentListPara, String userId, boolean isAdmin, boolean isFullAdmin);

    /**
     * 添加或者修改设备
     *
     * @param addEquipmentDTO
     * @return
     */
    Integer optEquipment(AddEquipmentDTO addEquipmentDTO, String userId);

    /**
     * 设备详情
     *
     * @param equipmentId
     * @return
     */
    SysEquipmentDetailsDTO equipmentDetails(String equipmentId, String userId, boolean isAdmin);

    /**
     * 删除设备
     *
     * @param equipmentIds
     * @return
     */
    Integer detele(List<String> equipmentIds, String userId);

    /**
     * 修改设备状态
     *
     * @param equipmentIds
     * @param userId
     * @return
     */
    Integer updateStatus(List<String> equipmentIds, Integer status, String userId);

    /**
     * 修改校准状态
     *
     * @param equipmentIds
     * @param userId
     * @return
     */
    Integer updateVerifyStatus(List<String> equipmentIds, String userId);

    /**
     * 批量修改设备IP
     *
     * @param userId
     * @return
     */
    Integer updateIps(UpdateEquipmentIdDTO updateEquipmentIdDTO, String userId);

    /**
     * 通过文件修改校准状态
     *
     * @param excelFile
     * @param userId
     * @return
     */
    AjaxResult updateVerifyStatusByFile(MultipartFile excelFile, String userId);

    /**
     * 设备控制
     *
     * @param equipmentIds
     * @param userId
     * @return
     */
    Integer equipmentControl(List<String> equipmentIds, String userId);

    /**
     * 导入设备
     *
     * @param file
     * @param userId
     * @return
     */
    AjaxResult equipmentExcelV2(MultipartFile file, String userId) throws IOException, InvalidFormatException;

    /**
     * 绑定情况
     *
     * @param equipmentId
     * @return
     */
    StationMiniInfo getEqBind(String equipmentId);

    List<EquipmentExportDTO> exportData(EquipmentListPara equipmentListPara, String userId, boolean isAdmin, boolean isFullAdmin);

    Long existEquipment(String equipmentId);

    /**
     * 获取所有气溶胶可用IP
     *
     * @return ip列表
     */
    List<String> getAerosolIpList();

    /**
     * 按业务种类查询需要同步的设备信息
     */
    List<EquipmentSyncDTO> findEquipmentSyncInfo(Integer businessType);

    /**
     * 按订单查询设备编号
     *
     * @param projectId 订单编号
     */
    List<EquipmentProjectInfoDTO> findByOrder(String projectId);

    /**
     * 查询设备项目信息
     *
     * @param equipmentId 设备编号列表
     */
    List<EquipmentProjectInfoDTO> findEquipmentOrderInfo(List<String> equipmentIds);

    /**
     * 设备编号筛选业务种类
     *
     * @param eidSet       设备编号集合
     * @param businessType 业务种类
     */
    Set<String> filterBusinessType(Set<String> eidSet, Integer businessType);

    /**
     * 根据产品类型查询设备
     *
     * @param productType
     * @return
     */
    List<String> equipmentByProductType(String productType);

    /**
     * 查询设备网关信息
     *
     * @param equipmentId 设备编号
     * @return
     */
    GatewayInfo gatewayInfo(String equipmentId);

    /**
     * 查询设备解码器
     */
    List<EquipmentDecoder> decoders(String equipmentId);

    /**
     * 查询设备解码消息
     */
    List<EquipmentDecodeMessage> decodeMessage(String equipmentId, Integer componentId);

}
